<?php
/**
 * Created by PhpStorm.
 * User: hooley
 * Date: 18-2-11
 * Time: 下午1:30
 */
namespace app\models;

use yii\base\Model;
use yii\web\UploadedFile;

/***
 * Class UploadForm
 * @package app\models
 * 上传表单模型
 */
class UploadForm extends Model
{
    /**
     * @var UploadedFile
     */
    public $imageFile;
    public $excel;//设置表单模型的excel属性


    public function rules()
    {
        return [
            [['excel'], 'file', 'skipOnEmpty' => false,// 'extensions' => 'png, jpg'
            ],
        ];
    }

    public function upload()
    {
        if ($this->validate()) {
            $filename=date('Ymd').\Yii::$app->getSecurity()->generateRandomString() . '.' . $this->excel->extension;
            //$filename="1.".$this->imageFile->extension;
            $this->excel->saveAs('uploads/excel/' .$filename);
            return $filename;
        } else {
            return false;
        }
    }
}